﻿using System;
using System.Collections.Generic;
using System.Text;

using Utils;
using Utils.Weixin.Pay;
using Utils.Weixin.Pay.Options;

namespace Microsoft.Extensions.DependencyInjection
{
    public static class WeChatPayExtensions
    {
        public static IServiceCollection AddWeChatPay(this IServiceCollection services, string secretKey)
        {
            return services
                .AddScoped(provider => ActivatorUtilities.CreateInstance<WeChatPay>(provider, ConvertOptions(provider.OptionsMonitor<SecretOptions>(secretKey))));
        }

        public static IServiceCollection AddWeChatPartnerPay(this IServiceCollection services, string secretKey)
        {
            return services
                .AddScoped(provider => ActivatorUtilities.CreateInstance<WeChatPartnerPay>(provider, ConvertOptions(provider.OptionsMonitor<SecretOptions>(secretKey))));
        }

        public static WeChatPayOptions ConvertOptions(SecretOptions secretOptions)
        {
            return secretOptions.ExtData.ToObject<WeChatPayOptions>();
        }
    }
}
